package com.yzx.lifeassistants.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.bean.MyBook;

/**
 * @Description: 已借阅图书适配器
 * @author: yzx
 * @time: 2016-3-8 下午5:09:13
 */
public class MyBookAdapter extends BaseAdapter {

	private List<MyBook> dataList;
	private MyBook data;
	private LayoutInflater inflater;
	private ViewHolder holder;

	public MyBookAdapter(Context context, List<MyBook> dataList) {
		this.dataList = dataList;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.item_my_book_listview,
					parent, false);
			holder = new ViewHolder();
			holder.nameTV = (TextView) convertView
					.findViewById(R.id.item_my_book_name_tv);
			holder.returnTimeTV = (TextView) convertView
					.findViewById(R.id.item_my_book_return_time_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		data = dataList.get(position);
		holder.nameTV.setText(data.getBookName());
		holder.returnTimeTV.setText("归还日期：" + data.getReturnTime());
		return convertView;
	}

	static class ViewHolder {
		TextView nameTV;// 书名
		TextView returnTimeTV;// 到期时间
	}
}
